<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改元素属性</title>
</head>
<body>
<div id="mydiv" style="width: 400px;height: 400px;background-color: palevioletred;margin:100px auto;"></div>
<script>
    var isclicked=false;
    var mydiv=document.getElementById("mydiv");
    mydiv.onclick=function(){
        if(!isclicked){
            mydiv.style.backgroundColor="#FFC0CB";
            isclicked=true;
        } else {
            mydiv.style.backgroundColor="#800080";
            isclicked=false;
        }
    }
</script>
</body>
</html>